#include "PauseMenu.h"

#include "GameApplication.h"
#include "GameView.h"

using namespace sf;
using namespace mega;

PauseMenu::PauseMenu()
	: Menu()
{
	m_shape = RectangleShape(Vector2f(300, 600));
	m_shape.setFillColor(Color(Uint8(128), Uint8(0), Uint8(0)));

	// create buttons
	m_items.push_back(new MenuItem(RectangleShape(Vector2f(200, 40))));
	m_items.back()->setText("CONTINUE");

	m_items.push_back(new MenuItem(RectangleShape(Vector2f(200, 40))));
	m_items.back()->setText("MAIN MENU");

	m_items.push_back(new MenuItem(RectangleShape(Vector2f(200, 40))));
	m_items.back()->setText("EXIT");

	// init items properties and expand
	initItems();
	expand();

	// TODO: move to the center of the screen
	this->move(Vector2f(300, 100));
}


PauseMenu::~PauseMenu()
{}


bool PauseMenu::onKeyReleased(const Keyboard::Key & _key)
{
	bool isHandled = false;

	return isHandled;
}


bool PauseMenu::onMouseReleased(const Mouse::Button & _button, const Position & _pos)
{
	bool isHandled = false;

	if (Mouse::Left == _button)
	{
		Position mousePos = gApp().window().mapPixelToCoords(Mouse::getPosition());

		// new game menu item clicked
		if (m_items.at(0)->getGlobalBounds().contains(mousePos))
		{
			gApp().popView();
			isHandled = true;
		}

		// go to main menu item clicked
		else if (m_items.at(1)->getGlobalBounds().contains(mousePos))
		{
			gApp().popView(); // location
			gApp().popView(); // main menu
			isHandled = true;
		}

		// exit menu item clicked
		else if (m_items.at(2)->getGlobalBounds().contains(mousePos))
		{
			gApp().window().close();
		}
	}

	return isHandled;
}
